package com.lagou.zookeeper;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.CreateMode;

public class Client2 {
	public static void main(String[] args) {
		try {
			RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
			CuratorFramework curatorFramework = CuratorFrameworkFactory.builder()
			.connectString("47.113.125.191:2181")
			.sessionTimeoutMs(50000)
			.connectionTimeoutMs(30000)
			.retryPolicy(retryPolicy)
			.namespace("servers") // 命名空间
			.build();
			curatorFramework.start();
			curatorFramework.create().creatingParentsIfNeeded().withMode(CreateMode.EPHEMERAL).forPath("/host2", "host2".getBytes());
			System.out.println("Server 2 Online");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
